<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">

		<title>人员管理</title>

		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">

		<link rel="stylesheet" type="text/css" href="css/themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="css/themes/icon.css">
		<link rel="stylesheet" type="text/css" href="js/demo.css">
		<script type="text/javascript" src="js/jquery-1.8.0.min.js"></script>
		<script type="text/javascript" src="js/jquery.easyui.min.js"></script>
		<link rel="stylesheet" type="text/css" href="css/usedcar.css">
    <script type="text/javascript">  
		$(document).ready(function(){
	 		$('#dg').datagrid({ 
				remoteSort : false,
				columns:[[  
				          {field:'username',title:'员工编号',width:80,align:'center', sortable:'true'},  
				          {field:'name',title:'姓名',width:80,align:'center', sortable:'true'},  
				          {field:'usercard',title:'身份证号',width:80,align:'center', sortable:'true'},  
				          {field:'tel',title:'手机号',width:200,align:'left', sortable:'true'},  
				          {field:'registerDate',title:'注册日期',width:80,align:'left', sortable:'true',
				        	  formatter:function(value,row){
									var str = row.registerDate;
									var m = str.month+1;
									var d = str.date;
									return (str.year+1900)+"-"+(m<10?('0'+m):m)+"-"+(d<10?('0'+d):d);
				        	  }}
				]],
	 			loader: function(param, success, error) {
		 			success(${WXpersons});
		 		}
	 		});
 		});
 		
        //var url;  
        function newUser(){  
            $('#dlg').dialog('open').dialog('setTitle','新增员工');  
            $('#fm').form('clear');
	        document.getElementById('fm').action="/aasimp/mok/maintenance/info_addPersons";  
             
			var date = new Date();
			var y = date.getFullYear();  
			var m = date.getMonth()+1;  
			var d = date.getDate();
			var h = date.getHours();
			var f = date.getMinutes();
			var s = date.getSeconds();
			$('#register_date').val(y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d)); 
			document.getElementById("U").checked = true;
        }  
        function editUser(){  
            var row = $('#dg').datagrid('getSelected');  
            if (row){  
                $('#dlg').dialog('open').dialog('setTitle','修改员工信息');  
                $('#username').val(row.username);
				document.getElementById("username").readOnly = true;
                $('#register_date').val(formatDate(row.registerDate));
                $('#name').val(row.name);
				document.getElementById(row.sex).checked = true;
                $('#usercard').val(row.usercard);
                $('#persontel').numberbox('setValue', row.tel);
	        	document.getElementById('fm').action='/aasimp/mok/maintenance/info_updatePersons?id='+row.userId; 
            }  
        }
        function formatDate(str){
			var m = str.month+1;
			var d = str.date;
        	return (str.year+1900)+"-"+(m<10?('0'+m):m)+"-"+(d<10?('0'+d):d);
        }  
        function saveUser(){
        	if($('#fm').form('validate')){
	            $('#fm').submit();
	            $('#dlg').dialog('close');
        	}   
        }  
        function destroyUser(){  
            var row = $('#dg').datagrid('getSelected');  
            if (row){  
                $.messager.confirm('提示','确定删除这条记录吗?',function(r){  
                    if (r){
                      	window.location = '/aasimp/mok/maintenance/info_destroyPersons?id='+row.userId; 
                    }  
                });  
            }  
        }  
    </script>  
	<style type="text/css">
		#main {
			width: 100%;
			height: 100%;
		}
        #fm{  
            margin:0;  
            padding:10px 30px;  
        }  
        .ftitle{  
            font-size:14px;  
            font-weight:bold;  
            padding:5px 0;  
            margin-bottom:10px;  
            border-bottom:1px solid #ccc;  
        }  
        .fitem{  
            margin-bottom:5px;  
        }  
        .fitem label{  
            display:inline-block;  
            width:80px;  
        }
        .panel-header, .panel-body {
		    border-width: 0px;
		}
    </style>

	</head>

<body>
<div id="main">
	<table id="dg" title="维修技术人员" class="easyui-datagrid" style="height:500px;"  
            toolbar="#toolbar"
            rownumbers="true" fitColumns="true" singleSelect="true">   
    </table>  
    <div id="toolbar">  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newUser()">新增</a>  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editUser()">编辑</a>  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyUser()">删除</a>  
    </div>  
      
    <div id="dlg" class="easyui-dialog" style="width:400px;height:350px;padding:10px 20px"  
            closed="true" buttons="#dlg-buttons">  
        <form id="fm" method="post">  
            <table>  
                <tr>  
                    <td>员工编号:</td>  
                    <td><input class="easyui-validatebox" type="text" id="username" name="username" data-options="required:true,missingMessage:'此项必填'"></input></td>  
                </tr>  
                <tr>  
                    <td>注册日期:</td>  
                    <td><input class="easyui-validatebox" type="text" id="register_date" name="register_date" readonly="readonly"></input></td>  
                </tr>  
                <tr>  
                    <td>姓名:</td>  
                    <td><input class="easyui-validatebox" type="text" id="name" name="name" data-options="required:true,missingMessage:'此项必填'"></input>
                    </td>  
                </tr>  
                <tr>  
                    <td>性别:</td>  
                    <td><INPUT type="radio" id=M value=M name="sex"/> 男&nbsp; 
					      <INPUT type="radio" id=F value=F name="sex"/> 女&nbsp; 
					      <INPUT type="radio" id=U value=U name="sex"/> 保密 </td>  
                </tr>  
                <tr>  
                    <td>身份证号:</td>  
                    <td><input class="easyui-validatebox" type="text" id="usercard" name="usercard" data-options="required:true,missingMessage:'此项必填'"></input>
				    </td>  
                </tr>  
                <tr>  
                    <td>手机号:</td>  
                    <td><input class="easyui-numberbox" id="persontel" name="persontel" data-options="
                    		required:true,
                    		missingMessage:'此项必填',
                    		validType:'maxLength[11]',  
				            onChange: function(value){  
				                $('#persontel').text(value);  
				            }">
				            <script type="text/javascript">
				            $.extend($.fn.validatebox.defaults.rules, {  
							    maxLength: {  
							        validator: function(value, param){  
							            return value.length <= param[0];  
							        },  
							        message: '最多输入{0}位'  
							    }  
							});
				            </script>
		            </td>  
                </tr>    
            </table>  
        </form>  
    </div>  
    <div id="dlg-buttons">  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveUser()">Save</a>  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">Cancel</a>  
    </div>  
</div>
</body>
</html>